﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH.PopUp.KhuyenMai
{
    public partial class popSuaGia : Form
    {
        private Int16 idg = -1;
        public popSuaGia(Int16 id)
        {
            InitializeComponent();
            idg = id;
        }

        public delegate void SuaGia(int outid);
        // khai báo 1 kiểu hàm delegate
        public SuaGia MyFunction;

        private void btsave_Click(object sender, EventArgs e)
        {
            if (MyFunction != null)
            {// tại đây gọi nó
                Int16 magia = Int16.Parse((txtidgia.Text.Trim() == "") ? "0" : txtidgia.Text.Trim());
                Int16 tuso = Int16.Parse((txtTuso.Text.Trim() == "") ? "0" : txtTuso.Text.Trim());
                Int16 toiso = Int16.Parse((txttoiso.Text.Trim() == "") ? "0" : txttoiso.Text.Trim());
                int gia = int.Parse((txtGia.Text.Trim() == "") ? "0" : txtGia.Text.Trim());

                clGia upgia = new clGia();
                int outid = upgia.update(idg, magia, tuso, toiso, gia);
                MyFunction(outid);
            }
            this.Close();
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void popSuaGia_Load(object sender, EventArgs e)
        {
            clGia lgia = new clGia();
            DataTable dtct = lgia.chitiet(idg);
            if (dtct != null && dtct.Rows.Count > 0)
            {
                txtidgia.Text = dtct.Rows[0]["idgia"].ToString();
                txtTuso.Text = dtct.Rows[0]["tuso"].ToString();
                txttoiso.Text = dtct.Rows[0]["toiso"].ToString();
                txtGia.Text = dtct.Rows[0]["gia"].ToString();
            }
        }
    }
}
